package com.TangoGames.sprite;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Point;

/**
 * @author Arthur
 *
 */
public class Sprite {

	/**
	 * 
	 */
	protected Bitmap bitmap;
	
	/**
	 * 
	 */
	protected Point offSetDraw = new Point(0,0); 
	
	public void setOffSetDraw(Point offSetDraw ){
		this.offSetDraw = offSetDraw;
	} 

	public Point getOffSetDraw() {
		return this.offSetDraw;
	} 
	
	public void centerDrawReference() {
		offSetDraw.x = bitmap.getWidth()/2;
		offSetDraw.y = bitmap.getHeight()/2;
	}
	/**
	 * 
	 */
	protected int x;			
	
	/**
	 * 
	 */
	protected int y;			
	
	/**
	 * 
	 */
	private float scale = 1.0f; 
	
	public float getScale() {
		return scale;
	}

	public void setScale(float scale) {
		this.scale = scale;
	}

	/**
	 * 
	 */
	private float rotate = 0.0f;

	public float getRotate() {
		return rotate;
	}

	public void setRotate(float rotate) {
		this.rotate = rotate;
	}
	
	/**
	 * 
	 */
	protected boolean touched;	
	
	/**
	 * 
	 * @param bitmap
	 * @param x
	 * @param y
	 */
	public Sprite(Bitmap bitmap, int x, int y) 
	{
		//
		this.bitmap = bitmap;
		
		//
		this.x = x;
		
		//
		this.y = y;
	}
	
	//saco de gets e sets...
	
	/**
	 * 
	 * @return
	 */
	public Bitmap getBitmap() 
	{
		//
		return bitmap;
	}
	
	/**
	 * 
	 * @param bitmap
	 */
	public void setBitmap(Bitmap bitmap)
	{
		//
		this.bitmap = bitmap;
		
	}
	
	/**
	 * 
	 * @return
	 */
	public int getX()
	{
		//
		return x;
	}
	
	/**
	 * 
	 * @param x
	 */
	public void setX(int x)
	{
		//
		this.x = x;
	}
	
	/**
	 * 
	 * @return
	 */
	public int getY()
	{
		//
		return y;
	}
	
	/**
	 * 
	 * @param y
	 */
	public void setY(int y) 
	{
		//
		this.y = y;
	}

	/**
	 * 
	 * @param canvas
	 */
	public void draw(Canvas canvas)
	{
		Matrix transf =  new Matrix();
		transf.postTranslate(this.x - offSetDraw.x , this.y - offSetDraw.y );
		if (rotate != 0.0f) { transf.preRotate( rotate , offSetDraw.x , offSetDraw.y ); }	
		//if (rotate != 0.0f) { transf.preRotate( rotate,  bitmap.getWidth()/2  ,  bitmap.getHeight()/2 );	}
		if (scale != 1.0f) 	{ transf.preScale(scale, scale); }		
		canvas.drawBitmap(bitmap, transf , new Paint(Paint.ANTI_ALIAS_FLAG));
	}
	
	public int getWidth() 	{ return bitmap.getWidth(); }
	
	public int getHeight() 	{ return bitmap.getHeight(); }
	
}
